package models;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

import play.data.format.Formats;
import play.data.validation.Constraints.MaxLength;
import play.data.validation.Constraints.Pattern;
import play.data.validation.Constraints.Required;
import play.db.ebean.Model;

import com.avaje.ebean.Page;

@Entity
public class Employee extends Model {

	private static final long serialVersionUID = 6073464634398034735L;

	
	@Id
	public Long id;
	
	@Required
	public String firstname; 

	@Required
	public String lastname;

	@Required
	public String documentType;

	@Required
	@MaxLength(value = 8)
	public String document;

	@Formats.DateTime(pattern="yyyy-MM-dd")
	public Date birthday;
	

	@Formats.DateTime(pattern="yyyy-MM-dd")
	public Date entryDate;

	@Required
    @Pattern(value = "^[0-9]{2}-[0-9]{8}-[0-9]$", message = "A valid CUIL is required")
	public String CUIL;

	@ManyToOne
	public EmployeeType employeeType;
 
	@ManyToOne
	public UnionCategory unionCategory;
	 
	@ManyToOne
	public Profession profession;
	
	@ManyToOne
 	public Position position; 
 	
 	@Required
 	@ManyToOne
	public LegalEntity legalEntity;

	public Employee(String firstname, String lastname, String company, Information... informations) {
		
	        this.firstname = firstname;
	        this.lastname = lastname;
	       

	}

 
 
  
	
	   /**
     * Generic query helper for entity Computer with id Long
     */
    public static Finder<Long,Employee> find = new Finder<Long,Employee>(Long.class, Employee.class); 
    
 
    public static Page<Employee> page(int page, int pageSize, String sortBy, String order, String filter) {
        return 
            find.where()
                .ilike("firstname", "%" + filter + "%")
                .orderBy(sortBy + " " + order)
                .findPagingList(pageSize)
                .getPage(page);
    }


	public Long getId() {
		return id;
	}


	public void setId(Long id) {
		this.id = id;
	}


	public String getFirstname() {
		return firstname;
	}


	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}


	public String getLastname() {
		return lastname;
	}


	public void setLastname(String lastname) {
		this.lastname = lastname;
	}


	public String getDocumentType() {
		return documentType;
	}


	public void setDocumentType(String documentType) {
		this.documentType = documentType;
	}


	public String getDocument() {
		return document;
	}


	public void setDocument(String document) {
		this.document = document;
	}


	public Date getBirthday() {
		return birthday;
	}


	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}


	public String getCUIL() {
		return CUIL;
	}


	public void setCUIL(String cUIL) {
		CUIL = cUIL;
	}


	public EmployeeType getEmployeeType() {
		return employeeType;
	}


	public void setEmployeeType(EmployeeType employeeType) {
		this.employeeType = employeeType;
	}


	public UnionCategory getCategoryATSA() {
		return unionCategory;
	}


	public void setCategoryATSA(UnionCategory categoryATSA) {
		this.unionCategory = categoryATSA;
	}


	public Profession getProfession() {
		return profession;
	}


	public void setProfession(Profession profession) {
		this.profession = profession;
	}


	public Position getPosition() {
		return position;
	}


	public void setPosition(Position position) {
		this.position = position;
	}

 
	public Date getEntryDate() {
		return entryDate;
	}


	public void setEntryDate(Date entryDate) {
		this.entryDate = entryDate;
	}


	public UnionCategory getUnionCategory() {
		return unionCategory;
	}


	public void setUnionCategory(UnionCategory unionCategory) {
		this.unionCategory = unionCategory;
	}


	public LegalEntity getLegalEntity() {
		return legalEntity;
	}


	public void setLegalEntity(LegalEntity legalEntity) {
		this.legalEntity = legalEntity;
	}
    

}
